#ifndef _DDBUFFERBLOCK_H_
#define _DDBUFFERBLOCK_H_

typedef struct _tagDDBufferBlock
{
	unsigned char *pBuffer;
	unsigned long lLength;
	unsigned long lCapacity;

	_tagDDBufferBlock()
	{
		memset(this,0,sizeof(*this));
	}

	~_tagDDBufferBlock()
	{
		if( NULL != pBuffer )
		{
			delete[]pBuffer;
			pBuffer = NULL;
		}
		lLength   = 0;
		lCapacity = 0;
	}

	bool Resize(long lSize)
	{
		if( NULL != pBuffer )
		{
			delete[]pBuffer;
			pBuffer = NULL;
		}
		lLength   = 0;
		lCapacity = 0;

		pBuffer = new unsigned char[lSize];
		if( NULL == pBuffer )
		{
			return false;
		}
        lCapacity = lSize;
		
		return true;
	}

	bool Enlarge(unsigned long lNewSize)
	{
		if( lNewSize > lCapacity )
		{
           unsigned char *pNewBuffer = new unsigned char[lNewSize];
		   if( NULL == pNewBuffer )
		   {
			   return false;
		   }

		   if( NULL != pBuffer )
		   {
			   memcpy(pNewBuffer,pBuffer,lLength);

			   delete[]pBuffer;
		   }

		   lCapacity = lNewSize;
		   pBuffer = pNewBuffer;
		}

		if( NULL != pBuffer )
		{
			return true;
		}
		
		return false;
	}

}DDBufferBlock;


#endif